<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/4
 * Time: 13:43
 */

namespace app\admin\controller\common;
use think\Db;

class Punav
{
    #返回后台导航
    public function re_nav_list($where = ['nav.id'=>['>',0]])
    {
        $data =  Db::table('bg_sysmenu')
            ->alias('nav')
            ->where($where)
            ->order('nav.parentId asc')
            ->join('q_words parent','nav.parentId = parent.id')
            ->field("
            nav.id as navid,/*主键*/
            nav.parentId as navparentId,/*父id*/
            nav.name as navname,/*导航名称*/
            nav.url as navurl,/*跳转地址*/
            nav.sortCode as navsortCode,/*排序*/
            nav.addtime as navaddtime,/*添加时间*/
            nav.show as navshow,/*是否显示导航*/
            nav.id as navid,/*主键*/
            parent.id as parentid,/*主键*/
            parent.code as parentcode,/*编码*/
            parent.name as parentname,/*名称*/
            parent.addtime as parentaddtime,/*创建时间*/
            parent.memo as parentmemo,/*配注*/
            parent.title as parenttitle/*用途*/
            ")
            ->select();
        return $this ->array_list($data,'navparentId');
    }


    /**根据相同的值 来分组
     * @param $array 数组
     * @param $name  比较的键名
     */
    public function array_list($array,$name)
    {
        $data = [];
        $index = -1;
        $info = 0;
        for ($i = 0; $i < count($array); $i++) {
            if($info != $array[$i][$name]){
                $index++;
                $info = $array[$i][$name];
            }
            $data[$index][] =$array[$i];
        }
        return $data;
    }


}